.NET RESTful Engine Custom Processing Reference
As of .NET RESTful Engine version 21.3, we now offer the ability to preform custom processing on your generated document before we mark it as done and ready for delivery. You can find a sample custom processing project to use for testing, and later implementing your own, on our github.
Requirements
In order to implement your own custom processing plugin for the .NET RESTful Engine, you will need the following:
- .NET RESTful engine version 21.3+
- WindwardCustomProcessing.dll -You will find this dll in the bin folder in the .NET RESTful engine installation The WindwardCustomProcessing.dll contains the following:
- IDocumentPostProcessor: This is the interface that you will implement
- CustomDocument: This is the model used as the data transfer object between the .NET RESTful engine and your defined custom plugin
- CustomProcessingTestUtil Class: This class contains methods that will help you test your custom code before using it in the .NET RESTful Engine.
Setting It Up
Create a new C# project and add the dll to the project dependencies. You can do that by right clicking on references, then add reference, then browse to find the WindwardCustomProcessing dll in the bin folder of your .NET RESTful Engine installation.
Keep the WindwardCustomProcessing dll in the bin folder. If you wish to have it in a separate location, make a copy of the dll and leave the original in the bin folder.
Then include the libraries to your class file, and define a class that implements IDocumentPostProcessor:
using WindwardCustomProcessing;
namespace CustomProcessing
{
public class PostProcess: IDocumentPostProcessor
.
.
.
The IDocumentPostProcessor only defines one method that you must implement:
Task<CustomDocument> Process(CustomDocument document);
This is an async method that takes in a CustomDocument object. These are the member variables in the CustomDocument model:
/*The generated report as a single file in the user specified format. If this is populated Pages will be null. */
public virtual byte[] Data { get; set; }
/*The generated report as a distinct file per page in the user specified format. If this is populated Data will be null. This is produced by the image report generator and by the HTML report generator when it is in per page mode.*/
public virtual byte[][] Pages { get; set; }
You can use the process method to do your own custom processing on the generated reports data before it is marked as complete. Whatever processing you do, make sure to return a Task<CustomDocument>
.
Testing It
In the WindwardCustomProcessing.dll we provide a class (GenerateDocumentModel) that has the following method:
public CustomDocument GetDocument(String path)
This method will return an object similar to the one we will use in the .NET RESTful engine with your custom code. The method takes in the path for a docgen.complete file (the xml file for a generated report). So in order to use this method, you must initially produce output from the base .NET RESTful engine. Once you have done that, navigate to the directory where the .NET RESTful engine stores output. The default directory is:
C:\inetpub\wwwroot\RESTfulEngine\App_Data\requests
Then find the {guid}.docgen.complete
file, pass its absolute path into the GetDocument() method and it will return a CustomDocument object for you to test with.
To use this method, instantiate the class and call the method:
GenerateDocumentModel test = new GenerateDocumentModel();
CustomDocument customDoc = test.GetDocument("PATH_TO_.docgen.complete_FILE");
//The you can test out your custom processing code on customDoc
Using the Custom Processing Plugin
After you have defined and tested your implementation of IDocumentPostProcessor, you are now ready to inject it and use it in your production .NET RESTful Engine.
The first thing you need to do is compile your custom processor project into a dll. Once you have the dll, do the following in your .NET RESTful engine's web.config:
<appSettings>
<add key="postProcessor" value="PATH_TO_DLL!CLASS_NAME" />
</appSetings>
Where:
- PATH_TO_DLL is the path to your IDocumentPostProcessor.dll implementation (if there are spaces in the path, put it in quotes)
- CLASS_NAME is the full class name of your repository class:
- ie. if your namespace is CustomDocumentProcessor and your class is named DocumentProcessor, CLASS_NAME would be CustomDocumentProcessor.DocumentProcessor.